<!--
 * @FilePath     : /study_code/layui/8-3-3.html
 * @Description  : 较大模板放在 script type="text/html" 标签中
 * @Date         : 2025-04-09 09:33:26
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-09 09:39:51
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <!-- 1，模板 -->
    <script id="TPL" type="text/html">
      <h3>{{= d.name }}</h3>
      <p>性别：{{= d.sex ? '男' : '女' }}</p>
    </script>

    <!-- 2、容器 -->
    <div id="view"></div>

    <script src="/layui/dist/layui.js"></script>
    <!-- 3、渲染代码 -->
    <script>
      layui.use(function () {
        var laytpl = layui.laytpl
        // 数据
        var data = {
          name: '张三',
          sex: 1,
        }
        var getTpl = document.getElementById('TPL').innerHTML // 获取模板字符
        var elemView = document.getElementById('view') // 视图对象
        // 渲染并输出结果
        laytpl(getTpl).render(data, function (str) {
          elemView.innerHTML = str
        })
      })
    </script>
  </body>
</html>
